// request.js
const baseUrl = "https://huishou.68699.cn/app/index.php";

function request(options = {}) {
    uni.showLoading({
        title: "加载中..."
    });

    options.url = baseUrl + options.url;
    options.data = options.data || {};
    options.header = {
        "Content-Type": "application/json",
        "Content-Type": "application/x-www-form-urlencoded"
    };
    options.method = options.method || 'GET';
    options.dataType = options.dataType || 'json';

    return new Promise((resolve, reject) => {
        uni.request({
            ...options,
            success: (result) => {
                if (result.statusCode !== 200) {
                    return reject(result);
                }
                uni.hideLoading();
                let data = result.data;
                resolve(data);
            },
            fail: (error) => {
                reject(error);
            }
        });
    });
}

export default request;
